do some general cleanup.
// -*- C++ -*-
-// $Id: babeldata.h,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: babeldata.h,v 1.2 2009/07/31 18:32:32 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
debugLevel(-1),
inputBrowse(QString()),
outputBrowse(QString()),
- previewGmap(false)
+ previewGmap(false),
+ upgradeCheckMethod(0),
+ upgradeCheckTime(QDateTime(QDate(2001, 1, 1), QTime(0, 0)))
{
};
sg.addVarSetting(new StringSetting("app.outputBrowse", outputBrowse));
sg.addVarSetting(new BoolSetting("app.previewGmap", previewGmap));
+ sg.addVarSetting(new IntSetting("app.upgradeCheckMethod", upgradeCheckMethod));
+ sg.addVarSetting(new DateTimeSetting("app.upgradeCheckTime", upgradeCheckTime));
}
static const int noType;
QString inputBrowse, outputBrowse;
bool previewGmap;
+ int upgradeCheckMethod;
+ QDateTime upgradeCheckTime;
};
// -*- C++ -*-
-// $Id: filterdata.cpp,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: filterdata.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
if (speed) s += ",speed";
if (pack) s += ",pack";
if (merge) s += ",merge";
- if (split && (pack || merge)) s += ",split";
+ if (split && (pack || merge)) {
+ s += ",split";
+ if (splitTime > 0)
+ s += QString("=%1%2").arg(splitTime).arg("mhd"[splitTimeUnit]);
+ }
+ if (splitDist > 0) {
+ double d = splitDist;
+ char u = ' ';
+ if (splitDistUnit == 0) { // ft.
+ d /= 5280.0; u = 'm';
+ }
+ else if (splitDistUnit == 1) { //m
+ d /= 1000.0; u = 'k';
+ }
+ else if (splitDistUnit == 2) { //km
+ u = 'k';
+ }
+ else if (splitDistUnit == 3) { //m
+ u = 'm';
+ }
+ s += QString(",sdistance=%1%2").arg(d).arg(u);
+ }
+
if (start) s += QString(",start=%1").arg(optionDate(startTime, TZ));
if (stop) s += QString(",stop=%1").arg(optionDate(stopTime, TZ));
if (move) s += QString(",move=%1d%2h%3m%4s").arg(days).arg(hours).arg(mins).arg(secs);
// -*- C++ -*-
-// $Id: filterdata.h,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: filterdata.h,v 1.2 2009/07/31 18:32:32 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
stop(false),
pack(false), merge(false), split(false),
GPSFixes(false), GPSFixesVal(0),
- course(false), speed(false)
+ course(false), speed(false),
+ splitTime(0), splitTimeUnit(0),
+ splitDist(0), splitDistUnit(0)
{
titleString = "ACTIVE LOG #%Y%m%d";
stopTime = QDateTime::currentDateTime();
sg.addVarSetting(new IntSetting("trks.secs", secs));
sg.addVarSetting(new BoolSetting("trks.title", title));
sg.addVarSetting(new StringSetting("trks.titleString", titleString));
+ sg.addVarSetting(new IntSetting("trks.splitTime", splitTime));
+ sg.addVarSetting(new IntSetting("trks.splitTimeUnit", splitTimeUnit));
+ sg.addVarSetting(new IntSetting("trks.splitDist", splitDist));
+ sg.addVarSetting(new IntSetting("trks.splitDistUnit", splitDistUnit));
}
virtual QStringList makeOptionString();
bool pack, merge, split, GPSFixes;
int GPSFixesVal;
bool course, speed;
+ int splitTime, splitTimeUnit;
+ int splitDist, splitDistUnit;
};
//------------------------------------------------------------------------
// -*- C++ -*-
-// $Id: filterwidgets.cpp,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: filterwidgets.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
addCheckEnabler(ui.GPSFixesCheck, ui.GPSFixesCombo);
connect(ui.mergeCheck, SIGNAL(clicked()) , this, SLOT(mergeCheckX()));
+ connect(ui.splitCheck, SIGNAL(clicked()) , this, SLOT(OtherCheckX()));
connect(ui.packCheck, SIGNAL(clicked()), this, SLOT(packCheckX()));
connect(ui.startCheck, SIGNAL(clicked()), this, SLOT(OtherCheckX()));
connect(ui.stopCheck, SIGNAL(clicked()), this, SLOT(OtherCheckX()));
fopts << new IntSpinFilterOption(tfd.hours, ui.hoursSpin);
fopts << new IntSpinFilterOption(tfd.mins, ui.minsSpin);
fopts << new IntSpinFilterOption(tfd.secs, ui.secsSpin);
+ fopts << new IntSpinFilterOption(tfd.splitTime, ui.splitTimeSpin, 0, 1000);
+ fopts << new IntSpinFilterOption(tfd.splitDist, ui.splitDistSpin, 0, 5280);
fopts << new DateTimeFilterOption(tfd.startTime, ui.startEdit);
fopts << new DateTimeFilterOption(tfd.stopTime, ui.stopEdit);
fopts << new StringFilterOption(tfd.titleString, ui.titleText);
fopts << new ComboFilterOption(tfd.GPSFixesVal, ui.GPSFixesCombo);
+ fopts << new ComboFilterOption(tfd.splitTimeUnit, ui.splitTimeCombo);
+ fopts << new ComboFilterOption(tfd.splitDistUnit, ui.splitDistCombo);
setWidgetValues();
checkChecks();
}
{
ui.TZCheck->setEnabled(ui.stopCheck->isChecked() || ui.startCheck->isChecked());
ui.splitCheck->setEnabled(ui.mergeCheck->isChecked() || ui.packCheck->isChecked());
+ bool bb = ui.packCheck->isChecked() &&ui.splitCheck->isChecked();
+ ui.splitTimeSpin->setEnabled(bb);
+ ui.splitTimeCombo->setEnabled(bb);
+ //ui.splitDistSpin->setEnabled(bb);
+ //ui.splitDistCombo->setEnabled(bb);
}
+
//------------------------------------------------------------------------
void TrackWidget::mergeCheckX()
{
// -*- C++ -*-
-// $Id: mainwindow.cpp,v 1.1 2009/07/31 17:59:58 robertl Exp $
+// $Id: mainwindow.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
connect(ui.actionQuit, SIGNAL(triggered()), this, SLOT(closeActionX()));
connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(helpActionX()));
connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(aboutActionX()));
- connect(ui.actionCheckForUpgrade, SIGNAL(triggered()), this, SLOT(checkForUpgradeX()));
connect(ui.inputFormatCombo, SIGNAL(currentIndexChanged(int)),
this, SLOT(inputFormatChanged(int)));
//--- Restore from registry
restoreSettings();
+ upgrade = new UpgradeCheck();
+ upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, bd.upgradeCheckTime);
}
+//------------------------------------------------------------------------
+MainWindow::~MainWindow()
+{
+ if (upgrade)
+ delete upgrade;
+}
//------------------------------------------------------------------------
void MainWindow::loadDeviceNameCombos()
{
// Ideally, expost this in the UI. For now, just split the track
// if we've no recorded fixes for > 5 mins and we've moved > 300 meters.
- args << "-x";
- args << "track,pack,sdistance=0.3k,split=5m";
+ //args << "-x";
+ //args << "track,pack,sdistance=0.3k,split=5m";
args << "-o";
args << "gpx";
//------------------------------------------------------------------------
void MainWindow::closeActionX()
{
+ QDateTime wt= upgrade->getUpgradeWarningTime();
+ if (wt.isValid()) {
+ bd.upgradeCheckTime = wt;
+ }
saveSettings();
+ delete upgrade;
+ upgrade = 0;
qApp->exit(0);
}
//------------------------------------------------------------------------
void MainWindow::closeEvent(QCloseEvent*)
{
- fprintf(stderr, "Close happened\n");
closeActionX();
}
//------------------------------------------------------------------------
{
ShowHelp("gpsbabel.html");
}
-void MainWindow::checkForUpgradeX()
-{
- Upgrade *foo = new Upgrade(this);
- foo->show();
- foo->checkForUpgrade();
-}
//------------------------------------------------------------------------
void MainWindow::filtersClicked()
{
// -*- C++ -*-
-// $Id: mainwindow.h,v 1.1 2009/07/31 17:59:58 robertl Exp $
+// $Id: mainwindow.h,v 1.2 2009/07/31 18:32:32 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
#include "format.h"
#include "filterdata.h"
#include "babeldata.h"
+#include "upgrade.h"
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget* parent);
- QString getBabelVersion(void) {return babelVersion;}
+ ~MainWindow();
private:
Ui_MainWindow ui;
QList<Format> formatList;
+ QString babelVersion;
QPixmap lights[4];
QStringList charSets;
- QString babelVersion;
AllFiltersData filterData;
BabelData bd;
bool fmtChgInterlock;
void updateFilterStatus();
void setWidgetValues();
void getWidgetValues();
+ UpgradeCheck *upgrade;
protected:
void closeEvent(QCloseEvent*);
void applyActionX();
void aboutActionX();
void helpActionX();
- void checkForUpgradeX();
void closeActionX();
void filtersClicked();
void resetFormatDefaults();
<x>0</x>
<y>0</y>
<width>674</width>
- <height>22</height>
+ <height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<addaction name="actionHelp"/>
<addaction name="separator"/>
<addaction name="actionAbout"/>
- <addaction name="actionCheckForUpgrade"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuHelp"/>
<string>Quit</string>
</property>
</action>
- <action name="actionCheckForUpgrade">
- <property name="text">
- <string>Check for Upgrade</string>
- </property>
- </action>
</widget>
<resources>
<include location="app.qrc"/>
<rect>
<x>0</x>
<y>0</y>
- <width>533</width>
- <height>251</height>
+ <width>558</width>
+ <height>218</height>
</rect>
</property>
<property name="windowTitle">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0" colspan="5">
+ <item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="font">
<font>
</property>
</widget>
</item>
- <item row="1" column="1" colspan="4">
+ <item row="1" column="1">
<widget class="QLineEdit" name="titleText">
<property name="toolTip">
<string>the title of the new track is composed of the start time of the track appended to this value. </string>
</property>
</widget>
</item>
- <item row="2" column="1" colspan="4">
- <layout class="QHBoxLayout" name="horizontalLayout">
+ <item row="2" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QSpinBox" name="daysSpin"/>
</item>
</property>
</widget>
</item>
+ </layout>
+ </item>
+ <item row="2" column="2">
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QSpinBox" name="hoursSpin"/>
</item>
</property>
</widget>
</item>
+ </layout>
+ </item>
+ <item row="2" column="3">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="minsSpin"/>
</item>
</property>
</widget>
</item>
+ </layout>
+ </item>
+ <item row="2" column="4">
+ <layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="secsSpin"/>
</item>
</property>
</widget>
</item>
+ <item row="5" column="3">
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
+ <item>
+ <widget class="QSpinBox" name="splitTimeSpin">
+ <property name="toolTip">
+ <string>If nonzero, the track will be split if the time between two points is greater than this parameter. If zero, the track will be split by date. </string>
+ </property>
+ <property name="maximum">
+ <number>500</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="splitTimeCombo">
+ <item>
+ <property name="text">
+ <string>mins</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>hrs</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>days</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="5" column="4">
+ <layout class="QHBoxLayout" name="horizontalLayout_7">
+ <item>
+ <widget class="QSpinBox" name="splitDistSpin">
+ <property name="toolTip">
+ <string>If nonzero, the input track will be split into several tracks if the distance between successive track points is greater than the distance given as a parameter. </string>
+ </property>
+ <property name="maximum">
+ <number>5280</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="splitDistCombo">
+ <item>
+ <property name="text">
+ <string>ft</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>m</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>km</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>mi</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
<item row="6" column="0" colspan="2">
<widget class="QWidget" name="widget_5" native="true">
<property name="toolTip">
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>83</width>
+ <width>1</width>
<height>20</height>
</size>
</property>
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>20</width>
- <height>25</height>
+ <width>10</width>
+ <height>2</height>
</size>
</property>
</spacer>
+// -*- C++ -*-
+// $Id: upgrade.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
/*
Copyright (C) 2009 Robert Lipe, robertlipe@gpsbabel.org
#include "upgrade.h"
-#include "mainwindow.h"
-#include "ui_upgrade.h"
#include <QHttp>
-#include <QUrl>
#include <QMessageBox>
-#include <QFile>
#include <QDomDocument>
-#include <QDomNode>
-#include <QDomElement>
-#include <QDomNodeList>
-Upgrade::Upgrade(QWidget *parent) :
- QDialog(parent),
- m_ui(new Ui::Upgrade)
+//static const bool testing = true;
+static const bool testing = false;
+
+static int versionAsNumber(const QString &s)
{
- m_ui->setupUi(this);
+ QStringList list = s.split(".");
+ return (list[0].toInt()<<16 | list[1].toInt() << 8 | list[2].toInt() );
}
-Upgrade::~Upgrade()
+UpgradeCheck::UpgradeCheck(QWidget *parent) :
+ QObject(parent),
+ http(0)
{
- delete m_ui;
}
-void Upgrade::changeEvent(QEvent *e)
+UpgradeCheck::~UpgradeCheck()
{
- QDialog::changeEvent(e);
- switch (e->type()) {
- case QEvent::LanguageChange:
- m_ui->retranslateUi(this);
- break;
- default:
- break;
- }
+ if (http) {
+ http->clearPendingRequests();
+ http->abort();
+ delete http;
+ http = 0;
+ }
}
-Upgrade::updateStatus Upgrade::checkForUpgrade()
+void UpgradeCheck::changeEvent(QEvent *)
{
- http = new QHttp;
+}
+
+UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tVersion,
+ int checkMethod,
+ const QDateTime &lastCheckTime)
+{
+ this->currentVersion = currentVersion;
+ this->upgradeCheckMethod = checkMethod;
+ QDateTime soonestCheckTime = lastCheckTime.addDays(1);
+ if (!testing && QDateTime::currentDateTime() < soonestCheckTime) {
+ // Not time to check yet.
+ return UpgradeCheck::updateUnknown;
+ }
+ http = new QHttp;
+
connect(http, SIGNAL(requestFinished(int, bool)),
this, SLOT(httpRequestFinished(int, bool)));
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
-
+
http->setHost("www.gpsbabel.org");
httpRequestId = http->get("/updates.xml");
-
- return Upgrade::updateUnknown;
+
+ return UpgradeCheck::updateUnknown;
}
-void Upgrade::readResponseHeader(const QHttpResponseHeader &responseHeader)
+void UpgradeCheck::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
switch (responseHeader.statusCode()) {
case 200: // Ok
case 302: // Found
case 303: // See Other
case 307: // Temporary Redirect
- // these are not error conditions
- break;
-
+ // these are not error conditions
+ break;
+
default:
- QMessageBox::information(this, tr("HTTP"),
- tr("Download failed: %1.")
- .arg(responseHeader.reasonPhrase()));
- httpRequestAborted = true;
- http->abort();
- }
+ QMessageBox::information(0, tr("HTTP"),
+ tr("Download failed: %1.")
+ .arg(responseHeader.reasonPhrase()));
+ httpRequestAborted = true;
+ http->abort();
+ }
}
-void Upgrade::httpRequestFinished(int requestId, bool error)
+void UpgradeCheck::httpRequestFinished(int requestId, bool error)
{
- if(error or requestId != httpRequestId) {
+ if (http == 0 || error)
+ return;
+
+ if (requestId != httpRequestId)
return;
- }
QString oresponse(http->readAll());
+
QDomDocument document;
- if (!document.setContent(oresponse)) {
+ if (!document.setContent(oresponse))
return;
- }
- QString response("snore");
+ QString response;
+
+ if (testing)
+ currentVersion = "1.3.1"; // for testing
- QString currentVersion = "1.3.6"; // FIXME: Work with Khai to pry this out of MainWindow
bool allowBeta = false; // TODO: come from prefs or current version...
+ int currentVersionNum = versionAsNumber(currentVersion);
+
QDomNodeList upgrades = document.elementsByTagName("update");
-
+
for (unsigned int i = 0; i < upgrades.length(); i++) {
QDomNode upgradeNode = upgrades.item(i);
QDomElement upgrade = upgradeNode.toElement();
-
+
QString updateVersion = upgrade.attribute("version");
bool updateIsBeta = upgrade.attribute("type") == "beta";
bool updateIsMajor = upgrade.attribute("type") == "major";
bool updateCandidate = updateIsMajor || (updateIsBeta && allowBeta);
+ int updateVersionNum = versionAsNumber(updateVersion);
+
+ if(updateVersionNum > currentVersionNum && updateCandidate) {
+ response = tr("<center><b>A new version of GPSBabel is available</b><br>"
+ "Your version is %1 <br>"
+ "The latest version is %2</center>")
+ .arg(currentVersion)
+ .arg(updateVersion);
- if(updateVersion > currentVersion && updateCandidate) {
- response = "<b>A new version of GPSBabel is available</b><br/ >";
- response += "Your version is " + currentVersion + " <br />";;
- response += "The latest version is " + updateVersion + " <br />";;
break;
}
}
-
- // FIXME: this doesn't actually write into the UI's text browser...
- m_ui->textBrowser->setText(response);
-
- //QMessageBox::information(this, tr("Finished"), response);
-
+ if (response.length()) {
+ QMessageBox::information(0, tr("Upgrade"), response);
+ upgradeWarningTime = QDateTime(QDateTime::currentDateTime());
+ }
+ delete http;
+ http = 0;
}
#include <QDialog>
-#include "ui_upgrade.h"
+#include <QDateTime>
+#include <QHttp>
class QHttp;
class QHttpResponseHeader;
-namespace Ui {
- class Upgrade;
-}
-
-class Upgrade : public QDialog {
+class UpgradeCheck : public QObject {
Q_OBJECT
public:
- Upgrade(QWidget *parent = 0);
- ~Upgrade();
+ UpgradeCheck(QWidget *parent = 0);
+ ~UpgradeCheck();
typedef enum {
updateUnknown,
updateNeeded,
} updateStatus;
- Upgrade::updateStatus checkForUpgrade(void);
+ UpgradeCheck::updateStatus checkForUpgrade(const QString &babelVersion,
+ int upgradeCheckMethod,
+ const QDateTime &lastCheckTime);
+ QDateTime getUpgradeWarningTime() {
+ return upgradeWarningTime;
+ }
protected:
void changeEvent(QEvent *e);
-private:
-// Ui::Upgrade *m_ui;
- Ui_Upgrade *m_ui;
+ private:
+ QString currentVersion;
+ int upgradeCheckMethod;
QHttp *http;
int httpRequestId;
bool httpRequestAborted;
QString latestVersion;
+ QDateTime upgradeWarningTime; // invalid time if this object never issued.
private slots:
void httpRequestFinished(int requestId, bool error);
+
// void httpStateChanged(int state);
void readResponseHeader(const QHttpResponseHeader &responseHeader);